package com.smartwebx.ha.web.admin.module.screen.report;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.dataresolver.Param;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.smartwebx.ha.biz.assign.HaDirectoryManager;
import com.smartwebx.ha.dal.assign.bean.HaDirectory;

/**
 * 
 * 创建人：Dream~天涯 
 * 创建时间：2015-4-22 下午10:55:37
 * 邮箱：154494796@qq.com
 * 备注：
 */
public class AjaxGetDrictoryIsLeaf {
	@Autowired
	private HttpServletResponse response;
	@Autowired
	private HaDirectoryManager haDirectoryManager;
	public void execute(@Param("directoryId") String directoryId) throws Exception{
		response.setContentType("application/json");
		PrintWriter out=response.getWriter();
		ObjectMapper mapper=new ObjectMapper();
		int id = Integer.parseInt(directoryId.substring(1, directoryId.length()));
		HaDirectory haDirectory = null;
		if(directoryId.indexOf('D')>=0||directoryId.indexOf('U')>=0){
			haDirectory = haDirectoryManager.select(id);
		}else if(directoryId.indexOf('A')>=0){
			haDirectory = haDirectoryManager.getDirectoryData("reportId", id, 1).get(0);
		}
		
		mapper.writeValue(out, "{isLeaf:"+haDirectory.getIsLeaf()+",code:"+haDirectory.getCode()+"}");
	}
}
